package com.lavegue.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.lavegue.common.BaseHibernateDao;
import com.lavegue.common.Page;
import com.lavegue.dao.BisGroupDao;
import com.lavegue.model.BisGroup;

/**
 * author: tianzhifen
 * date:2011-12-21
 * description:
 *
 */
public class BisGroupDaoImpl extends BaseHibernateDao<BisGroup, Integer> implements BisGroupDao{

	public BisGroupDaoImpl() {
		super(BisGroup.class);
	}
	
	//根据分组名称查询
    public Page<BisGroup> getAllBisGroupByNameAndTypeId(int pageNo,int pageSize,String name,int typeId)
    {
    	List<Criterion> condition = new ArrayList<Criterion>();
		if(null != name && !name.trim().equals("")){
		   condition.add(Restrictions.like("name", name, MatchMode.ANYWHERE));
		}
		if(typeId!=0){
			   condition.add(Restrictions.eq("bisType.id", typeId));
		}
		Page<BisGroup> page = this.findPage(pageNo, pageSize, condition, Order.desc("id"));
		return page;
    }

	public List<BisGroup> findGroupByType(int typeid) {
		return  this.getHibernateTemplate().find("from BisGroup where bisType.id=?", typeid);
	}
    
    
}

